package com.owc.common.redis;

import org.springframework.lang.NonNull;

public class CacheBuildKey {

    private static final String PREFIX = "api";

    private static final String LOCK_PREFIX = "lock";

    private static final String CACHE_PREFIX = ":";

    public static final Integer _TIME_SECOND_ONE = 1;

    public static final Integer _TIME_MINUTE_ONE = _TIME_SECOND_ONE * 60;

    public static final Integer _TIME_HOUR_ONE = _TIME_MINUTE_ONE * 60;


    private static String buildKey(Object str1, Object... array) {
        StringBuilder stringBuffer = new StringBuilder(PREFIX);
        stringBuffer.append(CACHE_PREFIX).append(str1);
        for (Object obj : array) {
            stringBuffer.append(CACHE_PREFIX).append(obj);
        }
        return stringBuffer.toString();
    }

    /**
     * Build register's verification code cache key
     */
    public static String buildRegisterAuthCodeCacheKey(String key){
        return buildKey("registerCode",key);
    }

    /**
     * Build login password verification code cache key.
     */
    public static String buildBackLoginPwdAuthCodeCacheKey(String key){
        return buildKey("backPwdCode",key);
    }

    public static String loginAuthCodeCacheKey(String key){
        return buildKey("loginCode",key);
    }

    public static String buildLockKey(String key){
        return buildKey(LOCK_PREFIX,key);
    }

    public static String buildTokenRefreshKey(String tokenName) {
        return buildKey("refreshStatus",tokenName);
    }

    public static String buildNoticeReadKey(Long userId) {
        return buildKey("readNoticeKey",userId);
    }

    /**
     * 每日已发放收益key
     */
    public static String buildSettlementIncomeKey(String date){
        return buildKey("incomeKey",date);
    }

    public static String buildIncomeJobLockKey() {
        return buildKey("incomeJobKey");

    }

    /**
     * Jwt 凭证维护队列
     * @param userId 用户ID
     */
    public static String buildUserJwtToken(@NonNull Long userId) {
        return buildKey("jwtToken",userId);
    }

    /**
     * 取消交易的hash缓存
     */
    public static String buildCancelOrderHashKey() {
        return buildKey("cancelOrderHash");
    }

    /**
     * 取消之后,新旧hash映射
     */
    public static String buildReplaceTxHashKey(String hash) {
        return buildKey("replaceHash",hash);
    }
}
